<?php

/* 文章 */

namespace Home\Controller;
use Think\Controller;
class ArticleController extends BaseController {
	public function index($a_id=0) {
        $Article=M('article');
        $this->Article = $Article->where(array('a_id' => $a_id))->find();
        $detail=$Article->find($a_id);
        $v['a_views'] = $detail['a_views'] + 1;
        $Article->where(array('a_id' => $a_id))->save($v);		
        $this->up = $Article->where('a_views !=0 AND a_id <' . $a_id)->order('a_id desc')->limit(1)->find();
        $this->down = $Article->where('a_views !=0 AND a_id >' . $a_id)->order('a_id')->limit(1)->find();
        $cate = M('article_cate')-> select();
        $this->assign('cate',$cate);
        //评论列表
        //$comment = M('comment')->where(array('cid'=>$a_id))->select();
        $Model = new \Think\Model();
        $comment = $Model->query("select a.id,pid,cid,uid,b.username,comment,b.picture from web_comment as a LEFT JOIN web_user AS b ON a.uid=b.id where cid='$a_id'");
        $comment = list_to_tree($comment);
        //var_dump($comment);exit;
        $this->assign('comment',$comment);
      	$this->display();
    }

    //文章评论
    public function comment(){
        if(session('uid')==''){
            $this->error('请先登录后再评论！',U('User/login'));
        }
        if($_POST['content']==''){
            $this->error('说点什么吧~');
        }
        $arr = array(
            'pid'=>$_POST['review_id'],
            'uid'=>$_POST['uid'],
            'cid'=>$_POST['cid'],
            'comment'=>$_POST['content'],
            'create_time' =>time()
        );
        $res = M('comment')->add($arr);
        $this->success('评论成功！');
    }

}

?>